{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #动态口令"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math #two-pointers #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学 #双指针 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: dynamicPassword"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #动态口令"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>某公司门禁密码使用动态口令技术。初始密码为字符串 <code>password</code>，密码更新均遵循以下步骤：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>设定一个正整数目标值 <code>target</code></li>\n",
    "\t<li>将 <code>password</code> 前 <code>target</code> 个字符按原顺序移动至字符串末尾</li>\n",
    "</ul>\n",
    "\n",
    "<p>请返回更新后的密码字符串。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> password = \"s3cur1tyC0d3\", target = 4\n",
    "<strong>输出:</strong> \"r1tyC0d3s3cu\"\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> password = \"lrloseumgh\", target = 6\n",
    "<strong>输出:&nbsp;</strong>\"umghlrlose\"\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= target&nbsp;&lt; password.length &lt;= 10000</code></li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [zuo-xuan-zhuan-zi-fu-chuan-lcof](https://leetcode.cn/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [zuo-xuan-zhuan-zi-fu-chuan-lcof](https://leetcode.cn/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"s3cur1tyC0d3\"\\n4', '\"vbzkgsaoiu\"\\n2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        pre_password = password[:target]\n",
    "        suffix_password = password[target:]\n",
    "\n",
    "        return suffix_password+pre_password"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, s: str, n: int) -> str:\n",
    "        return s[n:] + s[:n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        ans = password[target : len(password)] + password[0 : target]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        head = password[0:target]\n",
    "        tail = password[target:]\n",
    "        result = tail + head\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "       return password[target:]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        res=password[target:]+password[:target]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        str1 = password[0:target]\n",
    "        str2 = password[target:]\n",
    "        return str2+str1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:len(password)]+password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        # 确保目标值不超过密码长度\n",
    "        target = target % len(password)\n",
    "        # 将前 target 个字符移动至字符串末尾\n",
    "        updated_password = password[target:] + password[:target]\n",
    "        return updated_password"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "\n",
    "        pw_l = len(password)\n",
    "        count = 0\n",
    "        tmp1 = ''\n",
    "        tmp2 = ''\n",
    "        while pw_l and count < pw_l:\n",
    "\n",
    "            if count >= target:\n",
    "                tmp2 += password[count]\n",
    "            else:\n",
    "                tmp1 += password[count]\n",
    "\n",
    "            count += 1\n",
    "\n",
    "\n",
    "        return tmp2 + tmp1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        if target >= 0 and target < len(password):\n",
    "            s1 = password[:target]\n",
    "            s2 = password[target:]\n",
    "            s3 = s2 + s1\n",
    "        return s3.strip()\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        password = password[target:] + password[:target]\n",
    "        return password"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target: ] + password[:target]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        password = password[target:]+password[:target]\n",
    "        return password"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        sub=password[:target]\n",
    "        return password[target:]+sub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def dynamicPassword(self, password, target):\n",
    "        ans=password[target:]+password[:target]\n",
    "        return ans\n",
    "    # def reverseLeftWords(self, s: str, n: int) -> str:\n",
    "    #     res=[]\n",
    "    #     # 把 n~len(s)-1的部分添加到 res\n",
    "    #     for i in range(n,len(s)):\n",
    "    #         res.append(s[i])\n",
    "\n",
    "    #     # 再添加 0~ n-1的部分\n",
    "    #     for i in range(n):\n",
    "    #         res.append(s[i])\n",
    "    #     return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        str = password[target:]+password[:target]\n",
    "        return str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        str = password[target:]+password[:target]\n",
    "        return str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[:target] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        n = len(password)\n",
    "        s = password + password\n",
    "        return s[target:n+target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        prefix, suffix = password[:target], password[target:]\n",
    "        return suffix + prefix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        if target < len(password):\n",
    "           return password[target:] + password[0:target] \n",
    "        else:return password "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        lis = list(password)\n",
    "        for i in range(target):\n",
    "            a = lis[0]\n",
    "            lis.pop(0)\n",
    "            lis.append(a)\n",
    "        return ''.join(lis)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        n = len(password)\n",
    "        t = target % n\n",
    "        password = password[t:] + password[:t]\n",
    "        return password"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[0 : target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        if len(password) <= 1 : return password\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        # 使用列表\n",
    "        res = []\n",
    "\n",
    "        # # 添加前半部分\n",
    "        # for i in range(target, len(password)):\n",
    "        #     res.append(password[i])\n",
    "        \n",
    "        # # 添加后半部分\n",
    "        # for i in range(target):\n",
    "        #     res.append(password[i])\n",
    "\n",
    "        # 使用取余运算可以简化代码\n",
    "        for i in range(target, target + len(password)):\n",
    "            res.append(password[i % len(password)])\n",
    "\n",
    "        # 拼接\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        a=len(password)\n",
    "        b=password[0:target]\n",
    "        c=password[target:a]\n",
    "        d=c+b\n",
    "        return d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        res = []\n",
    "        n = len(password)\n",
    "        for i in range(target, n):\n",
    "            res.append(password[i])\n",
    "        for i in range(target):\n",
    "            res.append(password[i])\n",
    "        return ''.join(res)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        res=[]\n",
    "        for i in range(target,len(password)):\n",
    "            res.append(password[i])\n",
    "        for j in range(target):\n",
    "            res.append(password[j])\n",
    "        return \"\".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return (password + password)[target: target - len(password)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverse(self, s: List, start: int, end: int) -> None: # 左闭右闭\n",
    "        while start<end:\n",
    "            s[start],s[end]=s[end],s[start]\n",
    "            start+=1\n",
    "            end-=1\n",
    "    \n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        lst=list(password)\n",
    "        # 先局部反转，再整体反转\n",
    "        # self.reverse(lst,0,target-1)\n",
    "        # self.reverse(lst,target,len(password)-1)\n",
    "        # self.reverse(lst,0,len(password)-1)\n",
    "        # return \"\".join(lst)\n",
    "\n",
    "        # 整体，局部反转\n",
    "        self.reverse(lst,0,len(password)-1)\n",
    "        self.reverse(lst,0,len(password)-1-target)\n",
    "        self.reverse(lst,len(password)-target,len(password)-1)\n",
    "        return \"\".join(lst)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        if str == '':return ''\n",
    "        return password[target:len(password)]+password[:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:] + password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        return password[target:]+password[0:target]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, password: str, target: int) -> str:\n",
    "        words=[]\n",
    "        for i in range(len(password)-target):\n",
    "            words.append(password[i+target])\n",
    "        for i in range(target):\n",
    "            words.append(password[i])\n",
    "\n",
    "        return \"\".join(words)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dynamicPassword(self, pwd: str, n: int) -> str:\n",
    "        return pwd[n:] + pwd[0:n]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
